package com.wtzz.police.base.bean.req;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageDto {
    @NotNull(message = "pageIndex不能为空")
    @Min(value = 1, message = "pageIndex不符")
    @ApiModelProperty(value = "pageIndex", required = true)
    private Integer pageIndex;
    @NotNull(message = "pageSize不能为空")
    @Min(value = 1, message = "pageSize不符")
    @ApiModelProperty(value = "pageSize", required = true)
    private Integer pageSize;

    public PageRequest createPageRequest() {
        return PageRequest.of(pageIndex - 1, pageSize);
    }

    public PageRequest createPageRequest(Sort.Direction direction, String... properties) {
        return PageRequest.of(pageIndex - 1, pageSize, new Sort(direction, properties));
    }
}
